{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 读取数据文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a b c d\r\n",
      "d b b c\r\n",
      "a c\r\n",
      "e f b\r\n"
     ]
    }
   ],
   "source": [
    "cat doc.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把读取到的数据通过管道符 '|' 传递给 map 处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\r\n",
      "b\r\n",
      "c\r\n",
      "d\r\n",
      "d\r\n",
      "b\r\n",
      "b\r\n",
      "c\r\n",
      "a\r\n",
      "c\r\n",
      "e\r\n",
      "f\r\n",
      "b\r\n"
     ]
    }
   ],
   "source": [
    "cat doc.txt | python map.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过管道符 '|' 传递给系统函数 sort 进行排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\r\n",
      "a\r\n",
      "b\r\n",
      "b\r\n",
      "b\r\n",
      "b\r\n",
      "c\r\n",
      "c\r\n",
      "c\r\n",
      "d\r\n",
      "d\r\n",
      "e\r\n",
      "f\r\n"
     ]
    }
   ],
   "source": [
    "cat doc.txt | python map.py | sort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过管道符 '|' 传递给 reduce 进行统计次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a 2\r\n",
      "b 4\r\n",
      "c 3\r\n",
      "d 2\r\n",
      "e 1\r\n",
      "f 1\r\n"
     ]
    }
   ],
   "source": [
    "cat doc.txt | python map.py | sort | python reduce.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
